<template>
  <div class="app-header">
    <div class="title">手工艺品线上商城</div>
    <div class="search-container" @click="handleSearchClick">
      <div class="search-box">
        <input 
          type="text" 
          placeholder="请输入商品名称" 
          class="search-input" 
          v-model="searchText"
          @confirm="handleSearch"
          confirm-type="search"
        />
        <button class="search-btn" @click.stop="handleSearch">
          <span class="search-text">搜索</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AppHeader',
  data() {
    return {
      searchText: ''
    }
  },
  methods: {
    // 点击搜索框区域跳转
    handleSearchClick() {
      uni.navigateTo({
        url: '/pages/search/index'
      })
    },
    
    // 执行搜索跳转
    handleSearch() {
      if (!this.searchText.trim()) {
        uni.showToast({
          title: '请输入搜索内容',
          icon: 'none'
        })
        return
      }
      
      uni.navigateTo({
        url: `/pages/search/index?keyword=${encodeURIComponent(this.searchText)}`,
        success: () => {
          console.log('跳转成功，关键词:', this.searchText)
        }
      })
    }
  }
}
</script>

<style scoped>
.app-header {
  background-color: #2a5c54; /* 墨绿色背景 */
  padding: 15px 15px 20px;
  text-align: center;
}

.title {
  color: white;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 15px;
}

.search-container {
  padding: 0 15px;
}

.search-box {
  display: flex;
  width: 100%;
  height: 40px;
  background-color: white;
  border-radius: 20px;
  overflow: hidden;
  align-items: center;
}

.search-input {
  flex: 1;
  padding: 0 15px;
  border: none;
  outline: none;
  font-size: 14px;
  text-align: left;
  height: 100%;
}

.search-input::placeholder {
  color: #ccc;
}

.search-btn {
  width: 80px;
  height: 100%;
  background-color: #a8d8b9; /* 浅绿色 */
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  font-size: 16px;
}

.search-text {
  padding: 0 5px;
}
</style>